# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:derivative1_0.py
@Time:2024/8/2 9:55

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""
import numpy as np
import matplotlib.pyplot as plt

# 参数a和b
a = 1
b = 2

# x的范围
x = np.linspace(-5, 5, 400)

# 原始函数y = ax^2 + b
y = a * x**2 + b

# 导数函数dy/dx = 2ax
dy_dx = 2 * a * x

# 绘制原始函数
plt.plot(x, y, label=f'y = {a}x^2 + {b}')

# 绘制导数函数
plt.plot(x, dy_dx, label=f'dy/dx = {2*a}x', linestyle='--')

# 添加图例
plt.legend()

# 设置标题和坐标轴标签
plt.title('Function and Its Derivative')
plt.xlabel('x')
plt.ylabel('y')

# 显示网格
plt.grid(True)

# 显示图形
plt.show()